/**
 * 注册验证
 */
/* 检验用户名输入是否合法及用户名是否可以注册 */
function Validateusername() {
	var id = "username";
	var value = $("#" + id).val();
	if (!value) {
		document.getElementById("nameError").innerHTML = "<font color='red' size='3px'>用户名不能为空</font>";
		return false;
	}
	var reg = /^[a-zA-Z]{3,8}$/;
	var user_result = reg.exec(value);
	if (!user_result) {
		document.getElementById("nameError").innerHTML = "<font color='red' size='3px'>请输入正确的用户名</font>";
		return false;
	}
	$.ajax({
		type : "POST",
		url : "/B2CShop/CheckUser",
		async : false,
		cache : true,
		data : {
			name : value
		},
		dataType : "json",
		success : function(result) {
			if (!result) {
				document.getElementById("nameError").innerHTML = "<font color='green' size='3px'>&nbsp;输入正确</font>";
				return false;
			} else {
				document.getElementById("nameError").innerHTML = "<font color='red' size='3px'>&nbsp;用户名已存在</font>";
				return true;
			}
		}
	});
	return true;
}
/* 检验密码输入是否合法 */
function Checkpwd() {
	var id = "pwd";
	var value = $("#" + id).val();
	if (!value) {
		document.getElementById("pwdError").innerHTML = "<font color='red' size='3px'>密码不能为空</font>";
		return false;
	}
	var reg = /^[a-zA-Z0-9]{6,13}$/;
	var user_result = reg.exec(value);
	if (!user_result) {
		document.getElementById("pwdError").innerHTML = "<font color='red' size='3px'>请输入正确的密码</font>";
		return false;
	} else {
		document.getElementById("pwdError").innerHTML = "<font color='green' size='3px'>输入正确</font>";
		return true;
	}
	return true;
}
/*检验再次输入密码是否合法并且验证两次输入的密码是否一致*/
function Checkrepwd() {
	var id = "repwd";
	var value = $("#" + id).val();
	if (!value) {
		document.getElementById("repwdError").innerHTML = "<font color='red' size='3px'>密码不能为空</font>";
		return false;
	}
	var reg = /^[a-zA-Z0-9]{6,13}$/;
	var user_result = reg.exec(value);
	if (!user_result) {
		document.getElementById("repwdError").innerHTML = "<font color='red' size='3px'>请输入正确的密码</font>";
		return false;
	} else {
		if (value == $("#pwd").val()) {
			document.getElementById("repwdError").innerHTML = "<font color='green' size='3px'>两次输入的密码一致</font>";
			return true;
		} else {
			document.getElementById("repwdError").innerHTML = "<font color='red' size='3px'>两次输入的密码不一致</font>";
			return false;
		}
	}
	return true;
}
/*判断是否选择省份
function Checkprovince() {
	var id = "s_province";
	var value = $("#" + id).val();
	if (value == "省份") {
		document.getElementById("addressError").innerHTML = "<font color='red' size='3px'>省份不能为空</font>";
		return false;
	} else {
		document.getElementById("addressError").innerHTML = "";
		return true;
	}
}
判断是否输入地级市
function Checkcity() {
	var id = "s_city";
	var value = $("#" + id).val();
	if (value == "地级市") {
		document.getElementById("addressError").innerHTML = "<font color='red' size='3px'>地级市不能为空</font>";
		return false;
	} else {
		document.getElementById("addressError").innerHTML = "";
		return true;
	}
}
 判断是否输入市、县级市 
function Checkcounty() {
	var id = "s_county";
	var value = $("#" + id).val();
	if (value == "市、县级市") {
		document.getElementById("addressError").innerHTML = "<font color='red' size='3px'>市、县级市不能为空</font>";
		return false;
	} else {
		document.getElementById("addressError").innerHTML = "";
		return true;
	}
}*/
/* 判断邮政编码输入是否合法 */
function Checkzip() {
	var id = "zip";
	var value = $("#" + id).val();
	if (!value) {
		document.getElementById("zipError").innerHTML = "<font color='red' size='3px'>邮政编码不能为空</font>";
		return false;
	}
	var reg = /^[0-9]{6}/;
	var user_result = reg.exec(value);
	if (!user_result) {
		document.getElementById("zipError").innerHTML = "<font color='red' size='3px'>请输入正确的邮编</font>";
		return false;
	} else {
		document.getElementById("zipError").innerHTML = "<font color='green' size='3px'>输入正确</font>";
		return true;
	}
	return true;
}
/* 判断输入的家庭电话 */
function Checkphone() {
	var id = "phone";
	var value = $("#" + id).val();
	if (!value) {
		document.getElementById("phoneError").innerHTML = "";
		return false;
	}
	var reg = /^[0-9]{11}/;
	var user_result = reg.exec(value);
	if (!user_result) {
		document.getElementById("phoneError").innerHTML = "<font color='red' size='3px'>输入错误</font>";
		return false;
	} else {
		document.getElementById("phoneError").innerHTML = "<font color='green' size='3px'>输入正确</font>";
		return true;
	}
	return true;
}
/* 判断输入的手机号码 */
function Checkmobile() {
	var id = "mobile";
	var value = $("#" + id).val();
	if (!value) {
		document.getElementById("mobileError").innerHTML = "<font color='red' size='3px'>手机号不能为空</font>";
		return false;
	}
	var reg = /^[0-9]{11}/;
	var user_result = reg.exec(value);
	if (!user_result) {
		document.getElementById("mobileError").innerHTML = "<font color='red' size='3px'>不合法的手机号码</font>";
		return false;
	} else {
		document.getElementById("mobileError").innerHTML = "<font color='green' size='3px'>输入正确</font>";
		return true;
	}
	return true;
}
/* 判断真实姓名的输入 选填 */
function Checktruename() {
	var id = "truename";
	var value = $("#" + id).val();
	if (!value) {
		document.getElementById("truenameError").innerHTML = "";
		return false;
	}
	var reg = /^[\u4e00-\u9fa5_a-zA-Z_]{2,10}/;
	var user_result = reg.exec(value);
	if (!user_result) {
		document.getElementById("truenameError").innerHTML = "<font color='red' size='3px'>输入错误</font>";
		return false;
	} else {
		document.getElementById("truenameError").innerHTML = "<font color='green' size='3px'>输入正确</font>";
		return true;
	}
	return true;
}
/* 判断邮箱地址是否正确 */
function Checkemail() {
	var id = "email";
	var value = $("#" + id).val();
	//alert(value);
	if (!value) {
		document.getElementById("emailError").innerHTML = "<font color='red' size='3px'>邮箱地址不能为空</font>";
		return false;
	}
	//var reg = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/;
	var reg = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	var user_result = reg.exec(value);
	if (!user_result) {
		document.getElementById("emailError").innerHTML = "<font color='red' size='3px'>不合法的邮箱地址</font>";
		return false;
	} else {
		document.getElementById("emailError").innerHTML = "<font color='green' size='3px'>输入正确</font>";
		return true;
	}
	return true;
}
/* 判断表单提交是否合法 */
function checkregist() {
	var flaga = false;
	var flagb = false;
	var flagc = false;
	var flagg = false;
	var flagh = false;
	var flagi = false;
	var flagj = false;
	var flagk = false;

	/* 判断用户名输入 */
	if (Validateusername()) {
		flaga = true;
	}
	/* 判断密码输入 */
	if (Checkpwd()) {
		flagb = true;
	}
	/* 判断重复输入密码 */
	if (Checkrepwd()) {
		flagc = true;
	}
	/* 判断邮政编码 */
	if (Checkzip()) {
		flagg = true;
	}
	/* 判断家庭电话 */
	if (Checkphone()) {
		flagh = true;
	}

	/* 判断手机号码 */
	if (Checkmobile) {
		flagi = true;
	}
	/* 判断真实姓名 */
	if (Checktruename()) {
		flagj = true;
	}
	/* 判断邮箱地址 */
	if (Checkemail()) {
		flagk = true;
	}

	if (!flaga) {
		document.getElementById("nameError").innerHTML = "<font color='red' size='3px'>请输入正确的用户名</font>";
		return false;
	} else if (!flagb) {
		document.getElementById("pwdError").innerHTML = "<font color='red' size='3px'>请输入正确的密码</font>";
		return false;
	} else if (!flagc) {
		document.getElementById("repwdError").innerHTML = "<font color='red' size='3px'>请输入正确的密码</font>";
		return false;
	} else if (!flagg) {
		document.getElementById("zipError").innerHTML = "<font color='red' size='3px'>请输入正确的邮编</font>";
		return false;
	} else if (!flagh) {
		document.getElementById("phoneError").innerHTML = "<font color='red' size='3px'>请输入正确的家庭电话</font>";
		return false;
	} else if (!flagi) {
		document.getElementById("mobileError").innerHTML = "<font color='red' size='3px'>请输入正确的手机号码</font>";
		return false;
	} else if (!flagj) {
		document.getElementById("truenameError").innerHTML = "<font color='red' size='3px'>请输入正确的姓名</font>";
		return false;
	} else if (!flagk) {
		document.getElementById("emailError").innerHTML = "<font color='red' size='3px'>请输入正确的邮箱地址</font>";
		return false;
	} else if (flaga && flagb && flagc && flagg && flagh && flagi && flagj
			&& flagk) {
		return true;
	}
	return true;
}
